﻿/***************************************************************************

Copyright (c) Microsoft Corporation. All rights reserved.
This code is licensed under the Visual Studio SDK license terms.
THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.

***************************************************************************/

using System.Windows.Forms;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VsSDK.UnitTestLibrary;

namespace ConnectionStringCat_UnitTests.MenuItemTests
{
	internal static class UIShellServiceMock
	{
		private static GenericMockFactory uiShellFactory;

		#region UiShell Getters

		/// <summary>
		///     Returns an IVsUiShell that does not implement any methods
		/// </summary>
		/// <returns></returns>
		internal static BaseMock GetUiShellInstance()
		{
			if (uiShellFactory == null)
			{
				uiShellFactory = new GenericMockFactory("UiShell", new[] {typeof (IVsUIShell), typeof (IVsUIShellOpenDocument)});
			}
			var uiShell = uiShellFactory.GetInstance();
			return uiShell;
		}

		/// <summary>
		///     Get an IVsUiShell that implements SetWaitCursor, SaveDocDataToFile, ShowMessageBox
		/// </summary>
		/// <returns>uishell mock</returns>
		internal static BaseMock GetUiShellInstance0()
		{
			var uiShell = GetUiShellInstance();
			var name = string.Format("{0}.{1}", typeof (IVsUIShell).FullName, "SetWaitCursor");
			uiShell.AddMethodCallback(name, SetWaitCursorCallBack);

			name = string.Format("{0}.{1}", typeof (IVsUIShell).FullName, "SaveDocDataToFile");
			uiShell.AddMethodCallback(name, SaveDocDataToFileCallBack);

			name = string.Format("{0}.{1}", typeof (IVsUIShell).FullName, "ShowMessageBox");
			uiShell.AddMethodCallback(name, ShowMessageBoxCallBack);
			return uiShell;
		}

		#endregion

		#region Callbacks

		private static void SetWaitCursorCallBack(object caller, CallbackArgs arguments)
		{
			arguments.ReturnValue = VSConstants.S_OK;
		}

		private static void SaveDocDataToFileCallBack(object caller, CallbackArgs arguments)
		{
			arguments.ReturnValue = VSConstants.S_OK;
		}

		private static void ShowMessageBoxCallBack(object caller, CallbackArgs arguments)
		{
			arguments.ReturnValue = VSConstants.S_OK;
			arguments.SetParameter(10, (int) DialogResult.Yes);
		}

		#endregion
	}
}